package com.bzsg.simpleMediaPlayer.viewModel

import android.content.pm.ActivityInfo
import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.bzsg.simpleMediaPlayer.extend.requestIO
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import javax.inject.Inject

@HiltViewModel
class VideoStateViewModel
    @Inject
    constructor() : ViewModel() {
        // 全屏状态
        var isFullScreen by mutableStateOf(false)
            private set

        // 屏幕方向事件通道
        private val _orientationEvent = Channel<Int>()
        val orientationEvent = _orientationEvent.receiveAsFlow()

        // 切换全屏状态
        fun toggleFullScreen() {
            isFullScreen = !isFullScreen
            requestIO {
                _orientationEvent.send(
                    if (isFullScreen) {
                        ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                    } else {
                        ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                    },
                )
            }
        }
    }
